﻿@model thailandProject.Models.Triplet<int, int, thailandProject.Models.RESERVATION>

@{
    ViewBag.Title = "Add Client Payment";
}


<div id="Wrapper2">
    <div id="content_header">
        <div id="headerimage">
        </div>
        <div id="theheader">@ViewBag.Header</div>
    </div>
    <!-- Left Column begins here -->
    <aside id="sidebar-wrapper">
        <nav class="sidebar">
            <!-- CONTENT GOES HERE -->
            @using (Html.BeginForm("AddClientPayment", "Clients", FormMethod.Post, new { id = "paymentForm" }))
            {
                string check = "";
                string amount = "";
                string quotedPrice = "";
                string value = "false";
                if (Model.value3 != null)
                {
                    check = Model.value3.resIsHeld ? "checked=\"checked\"" : "";
                    amount = Model.value3.resIsHeld ? (Model.value3.resQuotedPrice / 2) + "" : "";
                    value = Model.value3.resIsHeld ? "true" : "false";
                    quotedPrice = Model.value3.resQuotedPrice.ToString();
                    quotedPrice = quotedPrice.Substring(0, quotedPrice.IndexOf('.') + 3);
                    if (!String.IsNullOrEmpty(amount) && amount.IndexOf('.') + 3 < amount.Length - 1)
                    {
                        amount = amount.Substring(0, amount.IndexOf('.') + 3);
                    }
                }
                <div id="taskNameArea">
                Reservation quoted price: &#3647; @quotedPrice
                <br /><br />
                <div id="amountDiv"><span  id="paymentAmountLabel">Amount: <span id="baht">&#3647;</span></span><br /><input type="text" id="paymentAmount" name="paymentAmount" maxlength="10" value="@amount" /><span style="color:red; visibility:hidden;">Invalid Amount</span></div><br />
                <div id="paymentTypeDiv">
                    <span  id="paymentTypeLabel">Type: </span><br />
                    <!--<input type="text" id="paymentType" name="paymentType" /> e.g. Credit Card, Cash, etc.-->
                    <select id="paymentType" name="paymentType">
                        <option>PayPal</option>
                        <option>Cash</option>
                        <option>Western Union</option>
                        <option>Wire Transfer</option>
                        <option>Other</option>
                    </select>
                </div><br />
                <div id="depositDiv"><span  id="paymentIsDepositLabel">Is Deposit: </span>
                    <span>
                        <input type="hidden" id="precheck" value="@value" />
                        <input id="paymentIsDeposit" name="paymentIsDeposit" type="hidden" value="@value" />
                        <img class="hideCompleted_checkbox" src="../../images/checkedBlue.png" id="checkbox" style="width:1.4em;"/>
                        <img src="../../images/unchecked.png" id="image_preload" style="width:1.4em; visibility:hidden;"/>   
                    </span>
                </div><br />
                </div>
                <div id="paymentDetailsArea">
                    <span id="taskDetailsLabel">Notes: </span><br /><textarea id="paymentNotesBox" name="paymentNotes" ></textarea>
                    <div id="taskDetailsCharsLeft">&nbsp;</div>
                </div>
                <input type="hidden" name="clientId" value="@Model.value1" />
                <input type="hidden" name="resId" value="@Model.value2" />
                
                <input type="image" src="../../images/add_button.png" id="addTaskButton" value="Add Payment" />
                <div id="submitError" style="color:red; visibility:hidden">Please fix errors before continuing.</div>
                <input type="hidden" id="delHeldRes" name="delHeldRes" value="false" />
                <input type="hidden" id="formcheck" value="false" />
            }
            <br />
            @Html.ActionLink("Back", "ViewClientPayments", new { clientId = Model.value1 })
        </nav>
    </aside>
    <!-- Right column begins here -->
    <article id="contents">
        
    </article>
    <!-- Right column ends here -->
</div>
<!-- Div wrapper2 ends here -->


<script type = "text/javascript">
    $(function () {
        $(".datepicker").datepicker();

        if ($("#precheck").val() == "false") {
            $("#checkbox").attr('src', '../../images/unchecked.png');
        }
    });

    $(".hideCompleted_checkbox").click(function () {
        var indicator = 0;
        var this_id = $(this).attr('id');
        //alert(this_id);
        if ($(this).attr('src') == '../../images/unchecked.png') {
            $(this).attr('src', '../../images/checkedBlue.png');
            $("#paymentIsDeposit").val('true');
            indicator = 1;
        }
        else {
            $(this).attr('src', '../../images/unchecked.png');
            $("#paymentIsDeposit").val('false');
            indicator = 0;
        }
    })

    $("#paymentAmount").keyup(function() {
        //Determine if the price is valid
        var price = $(this).val();
        if (isNaN(price) || price == "" || price.indexOf(' ') != -1 || price < 0) {
            $(this).next().attr('style', 'color:red; visibility:visible;');
        }
        else {
            $(this).next().attr('style', 'color:red; visibility:hidden;');
        }
    })

    $("#paymentNotesBox").keyup(function () {
        //Update the chars left counter
        var message = $(this).val();

        if (message.length > 2000) {
            message = message.substr(0, 2000);
            $(this).val(message);
        }

        $("#taskDetailsCharsLeft").text(2000 - message.length + " chars left");
    })

    $("#paymentForm").submit(function() {
        //Ensure that amount is a valid number
        var price = $("#paymentAmount").val();
        if (isNaN(price) || price == "" || price.indexOf(' ') != -1 || price < 0) {
            $("#submitError").attr('style', 'color:red; visibility:visible;');
            $("#paymentAmount").next().attr('style', 'color:red; visibility:visible;');
            $("#paymentAmount").focus();
            return false;
        }
        else {
            $("#submitError").attr('style', 'color:red; visibility:hidden;');
            $(this).next().attr('style', 'color:red; visibility:hidden;');

            //See if the user would like to delete unconfirmed reservations that overlap with this one
            if ($('#paymentIsDeposit').val() == 'true') {
                if (confirm("Would you like to delete unconfirmed reservations that are attached to this particular client?")) {
                    //Set the delHeldRes hidden
                    $("#delHeldRes").val('true');
                }
            }

            if ($("#formcheck").val() == 'false') {
                $("#formcheck").val('true');
                return true;
            }
            else {
                alert('Your action is currently being processed. Please wait');
                return false;
            }
        }
    })
</script>